﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media.Imaging;

namespace TheOliver.Controls
{
    public class GhostBehavior : Behavior<UIElement>
    {
        private UIElement _element;

        protected override void OnAttached()
        {
            _element = this.AssociatedObject;
            _element.MouseLeftButtonUp += new MouseButtonEventHandler(_element_MouseLeftButtonUp);
            base.OnAttached();
        }

        void _element_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ApplyEffect();
        }

        private void ApplyEffect()
        {
            int width = Convert.ToInt32(_element.DesiredSize.Width);
            int height = Convert.ToInt32(_element.DesiredSize.Height);
            WriteableBitmap wb = new WriteableBitmap(width, height);
            wb.Render(_element, _element.RenderTransform);

            // TODO:
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
        }
    }
}
